hbase单机安装和简单使用

电脑太卡了,使用不了hadoop和hdfs了,所以今天安装了一个伪分布式,数据存储在本地磁盘,也没有向HDFS中存,也没有使用自己的zookeeper,安装过程中还出了点小问题,总结一下,免得忘了。

1.hbase的安装

  ·将压缩包上传到linux中,解压,上传我使用的是secureCRT,直接ALT+P,然后从windows中下好的,拖进去就可以了。

  ·解压命令:tar -zxvf hbase.tar.gz

  ·修改配置文件,将目录切换到hbase/conf,修改第一个配置文件hbse-env.sh:这个文件修改两个位置,第一个是加入jdk,第二个是将zookeeper设置true【使用自带的,当然是可以使用自己的】

export JAVA_HOME=/home/kwhadoop/hadoop/jdk

export HBASE_MANAGES_ZK=true

  ·修改hbse-site.xml文件,将目录改到本地

<configuration>
        <property>
                <name>hbase.rootdir</name>
                <value>file:///home/kwhadoop/te</value>
        </property>
</configuration>

  ·启动命令

[root@hadoop bin]#./start-hbase.sh

  `启动shell

[root@hadoop bin]# ./hbase shell

  2018-03-30 18:40:12,322 INFO [main] Configuration.deprecation: hadoop.native.lib is deprecated. Instead, use io.native.lib.ava  ilable
  HBase Shell; enter 'help<RETURN>' for list of supported commands.
  Type "exit<RETURN>" to leave the HBase Shell
  Version 0.96.2-hadoop2, r1581096, Mon Mar 24 16:03:18 PDT 2014

  hbase(main):001:0>

(1)创建表

hbase(main):001:0> create 'user1','info1'
0 row(s) in 47.2280 seconds

=> Hbase::Table - user1

(2)显示表

hbase(main):004:0> list
TABLE                                                                                                                                                               
user1                                                                                                                                                               
1 row(s) in 0.0960 seconds

=> ["user1"]

(3)显示表结构

hbase(main):007:0> describe 'user1'
DESCRIPTION                                                                                               ENABLED                                                   
 'user1', {NAME => 'info1', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0' true                                                      
 , VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => '2147483647', KEEP_DELETED_CELLS =                                                           
 > 'false', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}                                                                                       
1 row(s) in 0.2010 seconds

(4)删除表的时候先要将表设置为disable,否则无法删除

hbase(main):008:0> drop 'user1'

ERROR: Table user1 is enabled. Disable it first.'

Here is some help for this command:
Drop the named table. Table must first be disabled:
  hbase> drop 't1'
  hbase> drop 'ns1:t1'

(5)将表设置为disable

hbase(main):008:0> disable 'user1'

(6)添加字段

hbase(main):002:0> put 'user1','1232456','info1:name','kw'
0 row(s) in 0.2550 seconds

(7)全表扫描

hbase(main):003:0> scan 'user1'
ROW                                        COLUMN+CELL                                                                                                              
 1232456                                   column=info1:name, timestamp=1522450895874, value=kw                                                                     
1 row(s) in 0.1910 seconds

(8)列族中增加字段

hbase(main):004:0> put 'user1','1232456','info1:age','23'
0 row(s) in 0.0270 seconds

hbase(main):005:0> scan 'user1'
ROW COLUMN+CELL
1232456 column=info1:age, timestamp=1522450938635, value=23
1232456 column=info1:name, timestamp=1522450895874, value=kw
1 row(s) in 0.0730 seconds

(9)统计行数

hbase(main):011:0> count 'user1'
1 row(s) in 0.1290 seconds

=> 1

(10)获取一个列族的数据

hbase(main):013:0> get 'user1','1232456','info1'
COLUMN                                     CELL                                                                                                                     
 info1:age                                 timestamp=1522450938635, value=23                                                                                        
 info1:name                                timestamp=1522450895874, value=kw                                                                                        
2 row(s) in 0.0400 seconds

(11)如果插入键值、列族、属性相同的属性,这个时候起到了更新的作用

hbase(main):018:0> put 'user1','1232456','info1:age','20'
0 row(s) in 0.0130 seconds

hbase(main):019:0> scan 'user1'
ROW                                        COLUMN+CELL                                                                                                              
 1232456                                   column=info1:age, timestamp=1522453126526, value=20                                                                      
 1232456                                   column=info1:name, timestamp=1522450895874, value=kw                                                                     
1 row(s) in 0.1330 seconds

(12)获取指定的属性,选取时间戳最新的数据显示

hbase(main):022:0> get 'user1','1232456','info1:age'
COLUMN                                     CELL                                                                                                                     
 info1:age                                 timestamp=1522453126526, value=20                                                                                        
1 row(s) in 0.0450 seconds

(13)删除数据

hbase(main):023:0> delete 'user1','1232456','info1:age'
0 row(s) in 0.2380 seconds

hbase(main):024:0> describe 'user1'
DESCRIPTION                                                                                               ENABLED                                                   
 'user1', {NAME => 'info1', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0' true                                                      
 , VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => '2147483647', KEEP_DELETED_CELLS =                                                           
 > 'false', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}                                                                                       
1 row(s) in 0.2180 seconds

hbase(main):025:0> scan 'user1'
ROW                                        COLUMN+CELL                                                                                                              
 1232456                                   column=info1:name, timestamp=1522450895874, value=kw                                                                     
1 row(s) in 0.0370 seconds

(14)删除所有

hbase(main):030:0> deleteall 'user1','1232456'
0 row(s) in 0.0210 seconds

hbase(main):031:0> list
TABLE
user1
1 row(s) in 0.1370 seconds

=> ["user1"]
hbase(main):032:0>

 

他只是将表中的列族删除了吗,表的删除需要使用disable,然后drop就可以了。

表都删了,那就不练了

 

  

posted @ 2018-03-30 23:49  kwdeep  阅读(6137)  评论(0编辑  收藏  举报